# 存放元素
import time

import allure
from selenium.webdriver.common.by import By
from base.base_page import Basspage
# yesmro商城前端
from utils.assert_util import assert_compare


# 企业中心左侧菜单功能
class Login(Basspage):
    """关于商城登录页面元素"""
    # 点击请登录
    my_login = (By.XPATH, '//*[@id="header"]/div[3]/div[1]/div/div[1]/div[1]/a[1]')
    # 点击密码登录
    click_password = (
        By.XPATH, '//*[@id="__layout"]/div/div[1]/div[2]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/span[2]')
    # 输入手机号
    my_phone = (
        By.XPATH,
        '//*[@id="__layout"]/div/div[1]/div[2]/div[1]/div[1]/div[2]/div[1]/div[1]/form/div[2]/div[1]/div/input')
    # 输入密码
    my_password = (
        By.XPATH,
        '//*[@id="__layout"]/div/div[1]/div[2]/div[1]/div[1]/div[2]/div[1]/div[1]/form/div[2]/div[2]/div/input')
    # 点击登录按钮
    click_login = (By.XPATH, '//*[@id="__layout"]/div/div[1]/div[2]/div[1]/div[1]/div[2]/div[1]/div[1]/button/span')
    # 登录后的用户名
    user_name = (By.XPATH, '//*[@id="header"]/div[3]/div[1]/div/div[1]/div[1]/a[3]')



    """顶部各tab元素"""
    # 点击企业询价单
    my_enquiry = (By.XPATH, '//*[@id="header"]/div[3]/div[1]/div/div[1]/div[2]/a[1]')
    # 点击报价中
    my_enquiry_quoted = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[1]/div/div[1]/a[2]')
    # 点击已报价
    my_enquiry_have_quoted = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[1]/div/div[1]/a[3]')
    # 点击已取消
    my_enquiry_cancel = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[1]/div/div[1]/a[4]')
    # 点击已过期
    my_enquiry_past_due = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[1]/div/div[1]/a[5]')
    # 点击企业订单
    my_order = (By.XPATH, '//*[@id="header"]/div[2]/div[1]/div/div[1]/div[2]/a[2]')
    # 点击待付款
    my_order_non_payment = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[2]/label')
    # 点击待发货
    my_order_not_yet_shipped = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[3]/label')
    # 点击部分发货
    my_order_part_shipments = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[4]/label')
    # 点击全部发货
    my_order_all_shipments = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[5]/label')
    # 点击已完成
    my_order_accomplish = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[6]/label')
    # 点击已取消
    my_order_cancel = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[7]/label')
    # 点击常用清单
    my_inventory = (By.XPATH, '//*[@id="header"]/div[2]/div[1]/div/div[1]/div[2]/a[3]')
    # 点击企业中心
    my_corporate_center = (By.XPATH, '//*[@id="header"]/div[2]/div[1]/div/div[1]/div[2]/a[4]')

    """企业中心，左侧菜单栏"""
    # 账户管理
    my_account = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[1]/div[1]/div[3]/div[2]/span')
    # 生产商认证
    my_manufacturer = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[1]/div[1]/div[4]/div[2]/span')
    # 黑卡专区
    my_Black_Card = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[1]/div[1]/div[5]/div[2]/span')
    # 发票清单
    my_invoice = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[1]/div[2]/div[5]/div[2]/span')
    # 申请售后
    my_after_sale = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[1]/div[2]/div[6]/div[2]/span')
    # 我的售后
    my_after = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[1]/div[2]/div[7]/div[2]/span')
    # 优惠卷
    my_discounts = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[1]/div[3]/div[2]/div[2]/span')
    # 发票信息
    my_invoice_message = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[1]/div[3]/div[4]/div[2]/span')
    # 收票信息
    my_invoice_ticket = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[1]/div[3]/div[5]/div[2]/span')

    """新增收货地址"""
    # 地址信息
    my_address = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[1]/div[3]/div[3]/div[2]/span')
    # 点击新增地址
    my_address_newly_increased = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[1]/div[4]/label')
    # 选择地址类型
    my_address_type = (By.XPATH,
                       '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[3]/div[1]/div/div/div/div/div[2]/div/div/form/div[1]/div/div/label[1]')
    # 联系人
    my_address_linkman = (By.XPATH,
                          '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[3]/div[1]/div/div/div/div/div[2]/div/div/form/div[2]/div/div/input')
    # 点击所在地区
    my_region_region = (By.XPATH, '//*[@id="address"]/div/div[1]/input')
    # 选择河北省
    my_hebei = (By.XPATH, '//li[contains(text(),"河北省")]')
    # 选择石家庄市
    my_shijiazhuang = (By.XPATH, '//li[contains(text(),"石家庄市")]')
    # 选择长安区
    my_Chang_an = (By.XPATH, '//li[contains(text(),"长安区")]')
    # 选择建北街道
    my_street = (By.XPATH, '//li[contains(text(),"建北街道")]')
    # 详细地址
    my_in_detail = (By.XPATH,
                    '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[3]/div[1]/div/div/div/div/div[2]/div/div/form/div[4]/div/div/input')
    # 手机号码
    my_region_mobile = (By.XPATH,
                        '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[3]/div[1]/div/div/div/div/div[2]/div/div/form/div[5]/div/div/input')
    # 点击确认
    my_region_notarize = (
        By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[3]/div[1]/div/div/div/div/div[3]/a[2]')
    # 收货地址新增成功提示
    my_newly_increased_succeed = (By.XPATH, '/html/body/div[12]/div/div/div[1]/div/span')

    """删除收货地址"""
    # 查找姓名为小姜的收货地址
    my_xiao_jiang = (By.XPATH, '//label[contains(text(),"小姜")]')
    # 鼠标悬浮到小姜的收货地址
    my_suspension = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div')
    # 点击删除
    my_delete = (By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/label[1]')
    # 弹窗点确认
    my_notarize = (
        By.XPATH, '//*[@id="__layout"]/div/div[2]/div[2]/div[2]/div[2]/div[4]/div[1]/div/div/div/div/div[3]/a[2]')
    # 提示删除成功!
    my_delete_succeed = (By.XPATH, '/html/body/div[12]/div/div/div[1]/div/span')


    # 登录
    def __init__(self, driver):
        super().__init__(driver)
        self.implicitly_wait = None

    def pu_login(self):
        self.get("https://www.yesmro.cn/")
        # 使用 JavaScript 执行点击
        # 使用 Selenium 的 execute_script 方法来直接通过 JavaScript 触发点击事件，这通常可以绕过被其他元素阻挡的问题。
        labels = self.find_element(self.my_login)
        self.driver.execute_script("arguments[0].click();", labels)
        self.click(self.click_password)
        self.send_keys(self.my_phone, "18910937327")
        self.send_keys(self.my_password, "jho123456")
        self.click(self.click_login)
        text = self.get_text(self.user_name)
        assert_compare("上海运横科技有限公司--UI自动化专用", '==', text)


